
<?php

define("CONFIG_FILE_PATH", "../data/config.ini");

function config_credential_path(){
    $arr = parse_ini_file(CONFIG_FILE_PATH, true);
    return $arr["WifiCredential"]["ListPath"];
}

function save_SimpleXMLElement_to_file($element, $path, $format=true){
    $f = fopen($path, "w") or die("When saving XML, unable to open file :".$path);
    if (!$format){
        $txt = $element->asXML();
    }else{
        $dom = new DOMDocument('1.0');
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = true;
        $dom->loadXML($element->asXML());
        $txt =  $dom->saveXML();
    }
    //fwrite($f, str_replace("\n\n", "\n", $txt));
    fwrite($f, $txt);
    fclose($f);
}

function load_xml_from_file($path){
    //this avoids error when loading file about 20% of the time
    libxml_disable_entity_loader(false);
    $ret = simplexml_load_file($path) or die ("problem loading XML file :".$path);
    return $ret;
}



?>
